package com.xuetang9.fujian.threaddemo;

/**
 * @author: fujian
 * @description: 阻塞当前线程，等待其他线程执行
 * @date: 2021/5/2 15:48
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo
 **/
public class JoinDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread printTask = new Thread(new PrintNumTask(),"打印线程");
        printTask.start();

        for (int i = 0; i < 20; i++) {
            if (i == 10){
                // 强势插入
                printTask.join();
                // 主线程会等子线程执行完毕
            }
            System.out.println(Thread.currentThread().getName() + "打印的数字," + i);
        }
    }
}
class PrintNumTask implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "打印的数字," + i);

        }
    }
}
